<!--
	时间：2019-01-12
	描述：采购订单追踪报表
-->

<!--<template>-->
<template>
	<div class="m-view-goodsAccountBill2 m-window">
		<!--查询条件-->
		<div class="m-condition">
			<el-row :gutter="10">
				<el-form
					:model="ruleForm"
					ref="ruleForm"
					label-width="70px"
					:inline-message="true"
					label-position="left"
				>
					<el-col :span="6">
						<el-form-item label="客户" class="rightItem" v-if="permission == 2">
							<el-select
								value-key="id"
								v-model="company"
								placeholder="请选择客户"
								@change="companyChange"
								filterable
							>
								<el-option
									v-for="item in comOptions"
									:key="item.id"
									:label="item.companyName"
									:value="item"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="公司" class="rightItem" v-if="permission == 1">
							<el-select
								value-key="id"
								v-model="company"
								placeholder="请选择公司"
								@change="companyChange"
								ref="content"
								filterable
							>
								<el-option
									v-for="item in comOptions"
									:key="item.id"
									:label="item.companyName"
									:value="item"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="4">
						<el-form-item label="入库日期" class="rightItem">
							<el-date-picker
								v-model="storageDateSt"
								type="date"
								placeholder="入库开始日期"
								value-format="yyyy-MM-dd"
							></el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="3">
						<el-date-picker
							v-model="storageDateEt"
							type="date"
							placeholder="入库结束日期"
							value-format="yyyy-MM-dd"
						></el-date-picker>
					</el-col>
					<el-col :span="4">
						<el-form-item label="订单日期" class="rightItem">
							<el-date-picker
								v-model="purOrdDateSt"
								type="date"
								placeholder="订单开始日期"
								value-format="yyyy-MM-dd"
							></el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="3">
						<el-date-picker
							v-model="purOrdDateEt"
							type="date"
							placeholder="订单结束日期"
							value-format="yyyy-MM-dd"
						></el-date-picker>
					</el-col>
                    <el-col :span="4" v-if="permission == 1">
						<el-form-item label="发布状态" class="rightItem" >
							<el-select value-key="id" v-model="postStatus" placeholder="请选择" clearable>
								<el-option
									v-for="(item,index) in postOptions"
									:key="index"
									:label="item.label"
									:value="item.value"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="4" v-if="permission == 2">
						<el-form-item label="交货状态" class="rightItem">
							<el-select value-key="id" v-model="comfirmStatus" placeholder="请选择" clearable>
								<el-option
									v-for="(item,index) in comfirmOptions"
									:key="index"
									:label="item.label"
									:value="item.value"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-form>
			</el-row>
			<el-row :gutter="10">
				<el-form
					:model="ruleForm"
					ref="ruleForm"
					label-width="70px"
					:inline-message="true"
					label-position="left"
				>
					<el-col :span="6" v-if="permission == 1">
						<el-form-item label="供应商" class="rightItem" >
							<el-input
								placeholder="请选择供应商"
								v-model="selCusName"
								clearable
								@focus="showSupplierDialog"
								readonly
								@mouseenter.native="mouseEnter"
								@mouseleave.native="mounseLeave"
							>
								<el-button slot="append" icon="el-icon-search" @click="showSupplierDialog"></el-button>
								<span slot="suffix" @click="inputClearSon" class="m-cleanInput" v-show="inputClearBut">
									<i class="el-input_icon el-icon-circle-close el-input__clear"></i>
								</span>
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="permission == 1?4:6">
						<el-form-item label="采购单号" class="rightItem">
							<el-input v-model="purOrdNo" placeholder="请输入采购订单号" @keyup.enter.native="search" clearable></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="3" v-if="permission == 1">
						<el-form-item label="采购组织" class="rightItem">
							<el-select value-key="id" v-model="purOrgCode" placeholder="请选择采购组织" clearable>
								<el-option
									v-for="(item,index) in purOrgOptions"
									:key="index"
									:label="item.purOrgName"
									:value="item.purOrgCode"
								></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="4" v-if="permission == 1">
						<el-form-item label="采购组" class="rightItem" >
							<el-input v-model="purGroup" placeholder="请输入采购组" @keyup.enter.native="search" clearable></el-input>
						</el-form-item>
					</el-col>
				</el-form>
				<el-col :span="2" class="m-floatRight">
					<el-button type="primary" @click="searchReport(1)">查询</el-button>
				</el-col>
			</el-row>
		</div>
		<!--采购订单跟踪列表-->
		<div class="m-agTable m-bottom m-top2">
			<agGridComponents
				ref="reportGridComponent"
				:getGridOptions="reportGridOptions"
				:getColumnDefs="reportColumnDefs"
				:getRowSelection="reportRowSelection"
				:isColFit="isColFit"
			></agGridComponents>
		</div>

		<!--送货单列表-->
		<el-dialog
			title="送货记录"
			:visible.sync="deliveryDialogVisible"
			width="80%"
			:before-close="deliveryClose"
			v-dialogDrag
			:close-on-click-modal="false"
			:close-on-press-escape="false"
		>
			<div class="m-agTableModel">
				<agGridComponents
					ref="deliveryGridComponent"
					:getGridOptions="deliveryGridOptions"
					:getColumnDefs="deliveryColumnDefs"
					:getRowSelection="deliveryRowSelection"
					:isColFit="isColFit"
				></agGridComponents>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-pagination
					@size-change="deliveryHandleSizeChange"
					@current-change="deliveryHandleCurrentChange"
					@prev-click="deliveryHandlePrevClick"
					@next-click="deliveryHandleNextClick"
					:current-page="deliveryCurrentPage"
					:page-sizes="[30,50,100,150,200]"
					:page-size="deliveryPageSize"
					layout="total, sizes, prev, pager, next, jumper"
					:total="deliveryTotal"
				></el-pagination>
			</div>
		</el-dialog>

		<!--入库单列表-->
		<el-dialog
			title="入库记录"
			:visible.sync="instockDialogVisible"
			width="80%"
			:before-close="instockClose"
			v-dialogDrag
			:close-on-click-modal="false"
			:close-on-press-escape="false"
		>
			<div class="m-agTableModel">
				<agGridComponents
					ref="instockGridComponent"
					:getGridOptions="instockGridOptions"
					:getColumnDefs="instockColumnDefs"
					:getRowSelection="instockRowSelection"
					:isColFit="isColFit"
				></agGridComponents>
			</div>
			<div slot="footer" class="dialog-footer"></div>
		</el-dialog>
		<!-- 供应商弹窗 -->
		<el-dialog
			title="供应商信息"
			:visible.sync="srmSupplierDialogVisible"
			width="50%"
			:before-close="srmSupplierDialogClose"
			v-dialogDrag
			:close-on-click-modal="false"
			:close-on-press-escape="false"
		>
			<srmSupplierInfo ref="srmSupplierInfo" :layout="layout" @setSrmSupplierInfo="setSrmSupplierInfo"></srmSupplierInfo>
		</el-dialog>
		<div class="m-page">
			<el-pagination
				@size-change="reportHandleSizeChange"
				@current-change="reportHandleCurrentChange"
				@prev-click="reportHandlePrevClick"
				@next-click="reportHandleNextClick"
				:current-page="reportCurrentPage"
				:page-sizes="[30,50,100,150,200]"
				:page-size="reportPageSize"
				layout="total, sizes, prev, pager, next, jumper"
				:total="reportTotal"
			></el-pagination>
		</div>
	</div>
</template>

<!--<script>-->
<script>
import _Api from "@/api";
import localeText from "@/i18n/agGridText";
import constant from "@/public/constant";
import agGridComponents from "@/components/agGridComponents.js";
import srmSupplierInfo from "@/components/srmSupplierInfo.vue";
import buttonLink from "@/components/buttonLink.js";

export default {
	data () {
		return {
			ruleForm: {},
			company: "", //公司编码
			// supplier: "", //供应商编码
			alertMessage: "", //消息提示
			purOrdNo: "", //采购订单号
			purOrdDateSt: "", //订单开始日期
			purOrdDateEt: "", //订单结束日期
			storageDateSt: "", //入库开始日期
			storageDateEt: "", //入库结束日期
			postStatus: "",//发布状态
			comfirmStatus: "",//交货状态
			purOrgCode: "",	//采购组织
			purGroup: "",	//采购组		
			comOptions: [], //公司列表
			suppliers: [],  //供应商列表
			purOrgOptions: [],//采购组织下拉列表
			postOptions: [{ value: 0, label: '未发布' }, { value: 1, label: '已发布' }],//发布状态下拉列表
			comfirmOptions: [{ value: 0, label: '未完成' }, { value: 1, label: '已完成' }, { value: 2, label: ' ' }],//交货状态下拉列表
			srmSupplierDialogVisible: false,//供应商弹窗可见性
			layout: {},
			selCusName: '',//选择的供应商名称
			selCusCode: '',//选择的供应商编码
			inputClearBut: false,
			reportGridOptions: "",
			reportColumnDefs: [],
			reportRowSelection: "multiple",
			reportCurrentPage: 1, //当前页码
			reportPageSize: 30, //页容量
			reportTotal: 0, //数据总量
			deliveryGridOptions: "",
			deliveryColumnDefs: [],
			deliveryRowSelection: "multiple",
			deliveryCurrentPage: 1, //当前页码
			deliveryPageSize: 30, //页容量
			deliveryTotal: 0, //数据总量
			deliveryDialogVisible: false, //可见性
			instockGridOptions: "",
			instockColumnDefs: [],
			instockRowSelection: "multiple",
			//instockCurrentPage: 1, //当前页码
			//instockPageSize: 30, //页容量
			//instockTotal: 0, //数据总量
			instockDialogVisible: false, //可见性
			selectData: {}, //选中数据
			permission: "",  //权限
			deliveryLoad: false,  //送货是否初次加载
			instockLoad: false,  //入库是否初次加载
			isColFit: true,
		}
	},
	created () {
		this.getAuthInfo()
		//默认供应商和公司的选项
		if (constant.accountType == 4)
			this.sel_Supplier_show = false;
		else
			this.sel_Supplier_show = true;
	},
	beforeMount () {
		this.gridOptions = {
			context: {
				componentParent: this
			},
			rowSelection: "single",
			enableColResize: true,
			localeText: localeText,
			suppressRowClickSelection: true,
		};

		this.isColFit = true;

		this.reportColumnDefs = [
			{ headerName: "id", field: "id", hide: true, width: 90 },
			{ headerName: "采购订单号", field: "purOrdNo", width: 500 },
			{ headerName: "行项目号", field: "purOrdMxNo", width: 150 },
			{ headerName: "供应商", field: "supplierCode", width: 150 },
			{ headerName: "供应商名称", field: "supplierName", width: 500 },
			{ headerName: "订单日期", field: "purOrdDate", width: 200 },
			{ headerName: "公司", field: "companyCode", width: 90 },
			{ headerName: "公司名称", field: "companyName", width: 500 },
			{ 
                headerName: "采购组织", 
                field: "purOrgName", 
                width: 150,
                cellRenderer:(params)=>{
                    if(params.value=='L001'){
                        return '材料供应部'
                    } else if(params.value=='L002'){
                        return '采购部'
                    } else if(params.value=='L003'){
                        return '商场采购部'
                    } else if(params.value=='L003'){
                        return '领尚环球'
                    }
                }
            },
			{ headerName: "采购组", field: "purGroupName", hide: this.permission == 2 ? true : false, width: 150 },
			{ headerName: "审核状态", field: "auditState", hide: true, width: 150 },
			{ headerName: "物料编号", field: "matCode", width: 200 },
			{ headerName: "物料描述", field: "matName", width: 500 },
			{ headerName: "订单数量", field: "orderAmount", width: 100 },
			{ headerName: "订单单位", field: "unitCode", width: 100 },
			{ headerName: "价格数量", field: "priceAmount", width: 100 },
			{ headerName: "价格单位", field: "priceUnit", width: 100 },
			{ headerName: "含税单价", field: "unitPrice", width: 100 },
			{ headerName: "含税金额", field: "unitMoney", width: 100 },
			{ headerName: "约定交货日期", field: "deliveryDate", width: 150 },
			{ headerName: "送货数量", field: "actualAmount", cellRenderer: buttonLink, width: 100 },
			{ headerName: "入库数量", field: "instockAmount", cellRenderer: buttonLink, width: 100 },
			{
				headerName: "交货完成",
				width: 120,
				field: "comFlag",
				cellRenderer: function (params) {
					if (params.value == 'X') return '<span class="ag-icon">已完成</span>';
					else return '<span class="ag-icon">未完成</span>';
				}
			},
			{ headerName: "备注", field: "remark", width: 150, tooltipField: 'remark' },
		];

		this.deliveryColumnDefs = [
			{ headerName: "id", field: "id", hide: true },
			{				headerName: "送货日期", field: "auditDate", width: 100, cellRenderer: function (params) {
					if (params.value)
						return new Date(Date.parse(params.value.replace(/-/g, "/"))).Format("yyyy-MM-dd");
				}			},
			{ headerName: "送货单单号", field: "deliveryNo", width: 150 },
			{ headerName: "送货单行号", field: "deliveryIMxNo", width: 100 },
			{ headerName: "送货数量", field: "actualAmount", width: 100 },
			{ headerName: "单位", field: "unitCode", width: 100 },
			{ headerName: "制单人", field: "creator", width: 200 },
			{ headerName: "审核人", field: "auditor", width: 200 }
		];

		this.instockColumnDefs = [
			{ headerName: "id", field: "id", hide: true },
			{ headerName: "送货单单号", field: "deliveryNo", width: 150 },
			// { headerName: "送货日期", field: "deliveryDate",width:100},
			{ headerName: "送货日期", field: "auditDate", width: 100 },
			{ headerName: "送货数量", field: "actualAmount", width: 100 },
			{ headerName: "入库日期", field: "auditDate", width: 100 },
			{ headerName: "入库单号", field: "instockNo", width: 100 },
			{ headerName: "行号", field: "instockMxNo", width: 100 },
			{ headerName: "入库数量", field: "instockAmount", width: 100 },
			{ headerName: "单位", field: "unitCode", width: 100 },
			{ headerName: "制单人", field: "creator", width: 100 },
			{ headerName: "审核人", field: "auditor", width: 100 }
		];
	},
	mounted () {
		// this.purOrgOptions = purOrgCode;
		if (constant.accountType == 1) {
			this.getPurOrgOptions()
		}
		this.$refs.reportGridComponent.rowDataChange = true;
	},
	components: {
		agGridComponents,
		srmSupplierInfo
	},
	methods: {
		// 选择公司名称回调
		companyChange (params) {
			if (this.permission == 1) {
				if (params) {
					this.layout.companyCode = params.companyCode;
					this.layout.auth = true;
					// this.layout.filterByUser = true;
					if (this.selCusCode)
						this.selCusCode = "";
					if (this.selCusName)
						this.selCusName = "";
				} else {
					this.layout = {};
					this.selCusName = "";
				}
			}
			// this.currentPage = 1;
		},
		// 打开供应商弹窗
		showSupplierDialog () {
			var that = this;
			if (!this.layout.companyCode) {
				this.$alert("提示：请选择公司！", {
					showClose: false,
					confirmButtonText: "确定",
					customClass: "alertPrompt"
				});
				this.$refs.content.focus();
				return;
			} else {
				this.srmSupplierDialogVisible = true;
				this.$nextTick(_ => {
					that.$refs.srmSupplierInfo.search();
				});
			}
		},
		// 关闭供应商弹窗回调
		srmSupplierDialogClose (done) {
			this.$refs.srmSupplierInfo.keyWord = "";
			this.$refs.srmSupplierInfo.selSupplierOptions.api.setQuickFilter(this.$refs.srmSupplierInfo.keyWord);
			done();
		},
		// 输入框清除事件监听
		inputClearSon () {
			this.selCusCode = "";
			this.selCusName = "";
			this.inputClearBut = false;
		},
		// 回显选择的供应商信息
		setSrmSupplierInfo (msg) {
			if (msg.length > 0) {
				this.srmSupplierDialogVisible = false;
				this.selCusCode = msg[0].supplierCode;
				this.selCusName = msg[0].supplierName;
			}
		},
		// 供应商输入框鼠标移入事件监听
		mouseEnter () {
			if (this.selCusName != "")
				this.inputClearBut = true;
		},
		// 供应商输入框鼠标移出事件监听
		mounseLeave () {
			if (this.selCusName != "")
				this.inputClearBut = false;
		},
		supplierChange () {
			this.searchReport();
		},
		reportHandleSizeChange (params) {
			this.reportPageSize = params;
			this.searchReport();
		},
		reportHandleCurrentChange (params) {
			this.reportCurrentPage = params;
			this.searchReport();
		},
		reportHandlePrevClick (params) {
			this.reportCurrentPage = params;
			this.searchReport();
		},
		reportHandleNextClick (params) {
			this.reportCurrentPage = params;
			this.searchReport();
		},
		deliveryHandleSizeChange (params) {
			this.deliveryPageSize = params;
			this.searchDelivery();
		},
		deliveryHandleCurrentChange (params) {
			this.deliveryCurrentPage = params;
			this.searchDelivery();
		},
		deliveryHandlePrevClick (params) {
			this.deliveryCurrentPage = params;
			this.searchDelivery();
		},
		deliveryHandleNextClick (params) {
			this.deliveryCurrentPage = params;
			this.searchDelivery();
		},
		//			instockHandleSizeChange(params){
		//				this.instockPageSize = params;
		//				this.searchInstock();
		//			},
		//			instockHandleCurrentChange(params){
		//				this.instockCurrentPage = params;
		//				this.searchInstock();
		//			},
		//			instockHandlePrevClick(params){
		//				this.instockCurrentPage = params;
		//				this.searchInstock();
		//			},
		//			instockHandleNextClick(params){
		//				this.instockCurrentPage = params;
		//				this.searchInstock();
		//			},
		deliveryClose (done) {
			done();
			this.deliveryTotal = 0;
			this.deliveryCurrentPage = 1;
			this.deliveryPageSize = 30;
		},
		instockClose (done) {
			done();
			this.instockTotal = 0;
			this.instockCurrentPage = 1;
			this.instockPageSize = 30;
		},
		searchReport (temp) {
			var that = this;
			if (temp === 1) {
				this.reportCurrentPage = 1;
			}
			var text = this.permission == 1 ? '公司' : '客户'
			if (!that.company) {
				that.$alert(`请选择${text}！`, {
					showClose: false,
					confirmButton: "确定",
					customClass: "alertPrompt"
				}).then(() => {
					return;
				});
			}
			// else if(!that.selCusCode){
			// 	that.$alert("请选择供应商！",{
			// 		showClose:false,
			// 		confirmButton:"确定",
			// 		customClass:"alertPrompt"
			// 	}).then(() => {
			// 		return;
			// 	});
			// } 
			else if (!this.purOrgCode && this.permission == 1) {
				that.$alert("请选择采购组织！", {
					showClose: false,
					confirmButton: "确定",
					customClass: "alertPrompt"
				}).then(() => {
					return;
				});
			}
			else if (that.postStatus === '') {
				that.$alert("请选择发布状态！", {
					showClose: false,
					confirmButton: "确定",
					customClass: "alertPrompt"
				}).then(() => {
					return;
				});
			} else if (this.postStatus === 0 && this.selCusName === '') {
				that.$alert("请选择供应商！", {
					showClose: false,
					confirmButton: "确定",
					customClass: "alertPrompt"
				}).then(() => {
					return;
				});
			}
			//jjc
			// else if(!that.storageDateSt){
			// 	that.$alert("请选择入库开始日期！",{
			// 		showClose:false,
			// 		confirmButton:"确定",
			// 		customClass:"alertPrompt"
			// 	}).then(() => {
			// 		return;
			// 	});
			// }
			// else if(!that.storageDateEt){
			// 	that.$alert("请选择入库结束日期！",{
			// 		showClose:false,
			// 		confirmButton:"确定",
			// 		customClass:"alertPrompt"
			// 	}).then(() => {
			// 		return;
			// 	});
			// }
			else {
				this.$refs.reportGridComponent.loading = true;
				if (this.postStatus == 0) {
					this.$refs.reportGridComponent.gridOptions.columnApi.setColumnVisible('auditState', true)
				} else {
					this.$refs.reportGridComponent.gridOptions.columnApi.setColumnVisible('auditState', false)
				}

				if (that.comfirmStatus == 2 || that.comfirmStatus === '') {
					_Api.getPurchaseReport({
						companyCode: that.company.companyCode,
						supplierCode: that.selCusCode,
						purOrdNo: that.purOrdNo,
						purOrdDateSt: that.purOrdDateSt,
						purOrdDateEt: that.purOrdDateEt,
						storageDateSt: that.storageDateSt,
						storageDateEt: that.storageDateEt,
						purOrgCode: that.purOrgCode,
						purGroup: that.purGroup,
						postStatus: that.postStatus,
						userType: that.permission,
						current: that.reportCurrentPage,
						size: that.reportPageSize,
					}).then(function success (response) {
						var data = response.data;
						if (data.code == 1) {
							if (data.total > 0) {
								that.$refs.reportGridComponent.gridOptions.api.setRowData(data.rows);
								that.reportTotal = data.total;
								that.$refs.reportGridComponent.loading = false;
							}
							else {
								that.$alert("没有找到相关数据", {
									showClose: false,
									confirmButton: "确定",
									customClass: "alertPrompt"
								}).then(() => {
									that.$refs.reportGridComponent.gridOptions.api.setRowData(data.rows);
									that.$refs.reportGridComponent.loading = false;
								});
                            }
                            that.reportTotal = data.total;
						}
						else {
							that.$alert(data.info, {
								showClose: false,
								confirmButton: "确定",
								customClass: "alertFailure"
							}).then(() => {
								that.$refs.reportGridComponent.loading = false;
								that.loading = false;
							});

						}
					},
						function error (err) {
							that.$alert("网络异常，查询失败！", {
								showClose: false,
								confirmButton: "确定",
								customClass: "alertFailure"
							}).then(() => {
								that.$refs.reportGridComponent.loading = false;
							});
						});
				} else {
					_Api.getPurchaseReport({
						companyCode: that.company.companyCode,
						supplierCode: that.selCusCode,
						purOrdNo: that.purOrdNo,
						purOrdDateSt: that.purOrdDateSt,
						purOrdDateEt: that.purOrdDateEt,
						storageDateSt: that.storageDateSt,
						storageDateEt: that.storageDateEt,
						purOrgCode: that.purOrgCode,
						purGroup: that.purGroup,
						postStatus: that.postStatus,
						userType: that.permission,
						current: that.reportCurrentPage,
						size: that.reportPageSize,
						comFlag: that.comfirmStatus == 1 ? 'X' : ''
					}).then(function success (response) {
						var data = response.data;
						if (data.code == 1) {
							if (data.total > 0) {
								that.$refs.reportGridComponent.gridOptions.api.setRowData(data.rows);
								that.reportTotal = data.total;
								that.$refs.reportGridComponent.loading = false;
							}
							else {
								that.$alert("没有找到相关数据", {
									showClose: false,
									confirmButton: "确定",
									customClass: "alertPrompt"
								}).then(() => {
									that.$refs.reportGridComponent.gridOptions.api.setRowData(data.rows);
									that.$refs.reportGridComponent.loading = false;
								});
							}
						}
						else {
							that.$alert(data.info, {
								showClose: false,
								confirmButton: "确定",
								customClass: "alertFailure"
							}).then(() => {
								that.$refs.reportGridComponent.loading = false;
								that.loading = false;
							});

						}
					},
						function error (err) {
							that.$alert("网络异常，查询失败！", {
								showClose: false,
								confirmButton: "确定",
								customClass: "alertFailure"
							}).then(() => {
								that.$refs.reportGridComponent.loading = false;
							});
						});
				}
			}
		},
		searchDelivery (data) {
			var that = this;
			if (this.deliveryLoad) this.$refs.deliveryGridComponent.loading = true;
			_Api.getDeliveryReportList({
				purOrdNo: this.selectData.purOrdNo,
				purOrdMxNo: this.selectData.purOrdMxNo,
				matCode: this.selectData.matCode,
				current: this.deliveryCurrentPage,
				size: this.deliveryPageSize,
			}).then(function success (response) {
				var data = response.data;
				if (data.code == 1) {
					that.$refs.deliveryGridComponent.gridOptions.api.setRowData(data.rows);
					that.deliveryTotal = data.total;
					that.$refs.deliveryGridComponent.loading = false;
				}
				else {
					that.$alert(data.info, {
						showClose: false,
						confirmButton: "确定",
						customClass: "alertFailure"
					}).then(() => {
						that.$refs.deliveryGridComponent.loading = false;
						that.loading = false;
					});

				}
			},
				function error (err) {
					that.$alert("网络异常，查询失败！", {
						showClose: false,
						confirmButton: "确定",
						customClass: "alertFailure"
					}).then(() => {
						that.$refs.deliveryGridComponent.loading = false;
					});
				});
		},
		searchInstock (data) {
			var that = this;
			if (this.instockLoad) this.$refs.instockGridComponent.loading = true;
			_Api.getInstockList({
				purOrdNo: this.selectData.purOrdNo,
				purOrdMxNo: this.selectData.purOrdMxNo,
				storageDateSt: this.storageDateSt,
				storageDateEt: this.storageDateEt
				//current: this.currentPage,
				//size: this.pageSize
			}).then(function success (response) {
				var data = response.data;
				if (data.code == 1) {
					that.$refs.instockGridComponent.gridOptions.api.setRowData(data.rows);
					//that.instockTotal = data.total;
					that.$refs.instockGridComponent.loading = false;
				}
				else {
					that.$alert(data.info, {
						showClose: false,
						confirmButton: "确定",
						customClass: "alertFailure"
					}).then(() => {
						that.$refs.instockGridComponent.loading = false;
						that.loading = false;
					});

				}
			},
				function error (err) {
					console.log(err.response)
					that.$alert("网络异常，查询失败！", {
						showClose: false,
						confirmButton: "确定",
						customClass: "alertFailure"
					}).then(() => {
						that.$refs.instockGridComponent.loading = false;
					});
				});
		},
		setClickValue (params) {
			this.selectData = params.data;
			if (params.column.colId == "actualAmount" && params.data.actualAmount != 0) {
				this.deliveryDialogVisible = true;
				this.searchDelivery();
			}
			else if (params.column.colId == "instockAmount" && params.data.instockAmount != 0) {
				this.instockDialogVisible = true;
				this.searchInstock();
			}
			else return;
		},
		getAuthInfo () {
			//获取当前账号权限公司
			var obj = {};
			//帐号类型：4为供应商
			if (this.$global.user.userTypeId == 4) {
				obj.account = this.$global.user.userName;
				obj.userType = 2;
				this.alertMessage = "请选择客户！";
				this.selCusCode = constant.supplierData.supplierCode;//设置默认供应商编码
				this.postStatus = 1;
				this.permission = obj.userType;
				let that = this
				this.$nextTick(() => {
					that.$refs.reportGridComponent.gridOptions.columnApi.setColumnVisible('supplierCode', false);
					that.$refs.reportGridComponent.gridOptions.columnApi.setColumnVisible('supplierName', false);
					that.$refs.reportGridComponent.gridOptions.columnApi.setColumnVisible('companyCode', false);
					that.$refs.reportGridComponent.gridOptions.columnApi.setColumnVisible('purOrgName', false);
				})
			}
			//帐号类型：1为内部员工
			else if (this.$global.user.userTypeId == 1) {
				obj.account = this.$global.user.oaNum;
				obj.userType = 1;
				this.alertMessage = "请选择公司！";
				this.permission = obj.userType;
			}
			var that = this;
			_Api.getAuthInfo(obj).then(function (response) {
				var data = response.data;
				if (data.code == 1) {
					//绑定公司选项
					if (data.rows.myMstCompany) that.comOptions = data.rows.myMstCompany;
					if (data.rows.myMstCompany) that.suppliers = data.rows.myMstSupplier;
				} else {
					that.comOptions = [];
				}
			}).catch((err) => {
				that.$alert(err.data.message, {
					showClose: false,
					confirmButton: "确定1",
					customClass: "alertFailure"
				});
				that.comOptions = [];
			})
		},
		// 获取采购组织
		getPurOrgOptions () {
			let params = {
				"userType": constant.accountType
			}
			_Api.getMstPurchaseorgList(params).then(res => {
				let data = res.data
				if (data.code == 1) {
					this.purOrgOptions = data.rows
					if (Array.isArray(this.purOrgOptions) && this.purOrgOptions.length > 0) {
						this.purOrgCode = this.purOrgOptions[0].purOrgCode
					}
				} else {
					this.$alert(data.info, {
						showClose: false,
						confirmButton: "确定",
						customClass: "alertFailure"
					})
				}
			})
				.catch(err => {
					this.$alert(err.data.message, {
						showClose: false,
						confirmButton: "确定",
						customClass: "alertFailure"
					});
				})
		}
	},
	props: {
		removeTab: {
			type: Function
		}
	},

}
</script>
